# set working directory to source file location

library(tidyverse)
library(kableExtra)

load("../Data/firm_comp.RData")

firm_comp %>% 
  ungroup %>% 
  group_by(reg_lobby_core_id, revolver) %>% 
  summarize_at(vars(rev_per_contract:rev_per_client), mean) %>% 
  ungroup %>% 
  group_by(revolver) %>% 
  summarize_at(vars(rev_per_contract:rev_per_client), mean) %>% 
  pivot_longer(-revolver) %>% 
  pivot_wider(names_from = "revolver") %>% 
  mutate(name = case_when(
    name == "total_contracts" ~ "Total Contracts",
    name == "total_clients" ~ "Total Clients",
    name == "total_rev" ~ "Total Revenue",
    name == "rev_per_contract" ~ "Revenue per Contract",
    name == "rev_per_client" ~ "Revenue per Client"
  )) %>% 
  mutate_at(vars(`0`:`1`), ~round(., 1)) %>% 
  kbl(
    caption = "Comparison of revolving lobbyists to non-revolving lobbyists within firms",
    label = "revolver_desc",
    col.names = c("", "Non-Revolver", "Revolver"),
    booktabs = T,
    "latex"
  ) %>% 
  save_kable(file = "../tables/TableA3.tex")

